package com.ilibrary.web.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.ilibrary.base.MyBaseAction;
import com.ilibrary.service.NewsCategoryService;
import com.ilibrary.service.NewsService;
import com.ilibrary.web.dto.ResultDto;
import com.ilibrary.web.vo.NewsCategoryVO;
import com.ilibrary.web.vo.NewsVO;

public class IndexAction extends MyBaseAction {
	
	private NewsService newsService;
	private NewsCategoryService newsCategoryService;
	
	public NewsService getNewsService() {
		return newsService;
	}
	public void setNewsService(NewsService newsService) {
		this.newsService = newsService;
	}
	public NewsCategoryService getNewsCategoryService() {
		return newsCategoryService;
	}
	public void setNewsCategoryService(NewsCategoryService newsCategoryService) {
		this.newsCategoryService = newsCategoryService;
	}
	
	@Override
	public String execute() throws Exception {
		HashMap<String, List<NewsVO>> newsListMap = new HashMap<String, List<NewsVO>>();
		ResultDto<NewsCategoryVO> resultDtoCat = null;
		List<NewsCategoryVO> newsCategoryVOList = null;
		resultDtoCat = newsCategoryService.findAll();
		newsCategoryVOList = resultDtoCat.getResultList();
		for (NewsCategoryVO newsCategoryVO : newsCategoryVOList) {
			ResultDto<NewsVO> resultDto = newsService.queryList(0, 10, newsCategoryVO.getNewsCategoryId(), null);
			List<NewsVO> newsVOList = resultDto.getResultList();
			newsListMap.put(newsCategoryVO.getNewsCategoryId(), newsVOList);
			//System.out.println(newsCategoryVO.getNewsCategoryId()+"/"+newsVOList.size());
		}
		getRQ().setAttribute("newsListMap", newsListMap);
		return SUCCESS;
	}
}
